package cn.terys.terystransactionclient;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import cn.emagsoftware.ui.ToastManager;
import cn.emagsoftware.ui.staticmanager.StaticManager;
import cn.emagsoftware.util.LogManager;
import cn.terys.terystransactionclient.data.User;
import cn.terys.terystransactionclient.data.UserManager;

public class ManageActivity extends BaseActivity
{

    public static final String INTENT_EXTRANAME_USER         = "USER";
    public static final String INTENT_EXTRANAME_VERIFYOLDPWD = "VERIFYOLDPWD";

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        if (!WelcomeActivity.IS_APP_RUNNING)
        {
            StaticManager.restartAppWhenDalvikRecycled(this, WelcomeActivity.class);
            return;
        }
        setContentView(R.layout.manage);
        setTitle(R.string.manage_title);
        Button edit = (Button) findViewById(R.id.edit);
        edit.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Intent intent = new Intent(ManageActivity.this, UserInputActivity.class);
                intent.putExtra(INTENT_EXTRANAME_USER, MainActivity.USER);
                startActivity(intent);
            }
        });
        Button editManager = (Button) findViewById(R.id.edit_manager);
        editManager.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                User manager = null;
                try
                {
                    manager = UserManager.getManagerUser();
                } catch (Exception e)
                {
                    LogManager.logE(ManageActivity.class, "getManagerUser error.", e);
                    ToastManager.showLong(ManageActivity.this, R.string.manage_edit_manager_get_exception);
                    return;
                }
                Intent intent = new Intent(ManageActivity.this, UserInputActivity.class);
                intent.putExtra(INTENT_EXTRANAME_USER, manager);
                intent.putExtra(INTENT_EXTRANAME_VERIFYOLDPWD, false);
                startActivity(intent);
            }
        });
        Button manage = (Button) findViewById(R.id.manage);
        manage.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Intent intent = new Intent(ManageActivity.this, OperatorManageActivity.class);
                startActivity(intent);
            }
        });
        if (MainActivity.USER.role != User.ROLE_BOSS)
        {
            editManager.setVisibility(View.GONE);
            manage.setVisibility(View.GONE);
        }
    }

}